import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

class InteractiveViewerPage extends StatefulWidget {
  const InteractiveViewerPage({super.key});

  @override
  State<InteractiveViewerPage> createState() => _InteractiveViewerPageState();
}

class _InteractiveViewerPageState extends State<InteractiveViewerPage> {
  final TransformationController _controller = TransformationController();

  void _handleDoubleTap() {
    // 双击切换缩放比例
    final scale = _controller.value.getMaxScaleOnAxis();
    _controller.value =
        scale == 2.0 ? Matrix4.identity() : Matrix4.identity()
          ..scale(2.0);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("InteractiveViewer Demo"),
        centerTitle: true,
        leading: IconButton(
          onPressed: () {
            context.pop();
          },
          icon: Icon(Icons.arrow_back_ios_rounded),
        ),
      ),
      body: Center(
        child: Column(
          children: [
            GestureDetector(
              onDoubleTap: _handleDoubleTap,
              child: InteractiveViewer(
                transformationController: _controller,
                maxScale: 4,
                child: Image.asset('assets/image/ic_logo.png'),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
